/**
 * copyright © geolabs 2006
 * author: Gérald Fenoy
 * 
 */

System.require("Styler");

/**
 * The Line class.
 */
Line=Class.create({id: 0});
Line.define({
  _init: function(A,B){
      bla=Array();
      this.id=Line.id;
      Line.id++;
      this.length = Math.sqrt( (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y) );
      for( i=0; i<this.length; i++ )
	{
	  var tmp=document.createElement("div");
	  tmp.setAttribute("id","line_"+this.id+"_"+i);
	  Styler.setStyle(tmp,"position:absolute;left:"+ Math.round( A.x+(B.x-A.x)*i/this.length  ) +"px;top:"+ Math.round( A.y+(B.y-A.y)*i/this.length ) +"px;width:1px;height:1px;background:#000");
	  document.body.appendChild(tmp);
	}
      this.startPoint=A;
      this.endPoint=B;
    },

  remove: function(){
      for(i=0;i<this.length;i++){
	try{
	  document.body.removeChild(document.getElementById("line_"+this.id+"_"+i));
	}catch(e){alert(this.id+" "+i);}
      }
    }
  })


/**
 * The MultiLine class
 */
MultiLine=Class.create({id: 0});
MultiLine.define({

  _init: function(){
      this.id=MultiLine.id;
      MultiLine.id++;
      this.lines=new Array();
    },

  append: function(l){
      this.lines.push(l);
    },

  remove: function(l){
      for(i=0;i<this.lines.length;i++)
	if(this.lines[i].id==l.id){
	  this.lines[i].remove();
	  this.lines.splice(i,1);
	}
    }

  })
